<?php $lass = 0; ?>
<?php if ($this->get('issearching')==1){ ?>
		<?php foreach($delist as $list){?>
			<?php if ($lass == $list['rotid']){ ?>
				<a style="color: #59b7c2;"><?php echo $list['name']; ?></a>, 
				<?php } else { ?>
					</span></td>
				</tr>
        		<tr class="list" style="height:40px;padding-top:10px" status="<?php echo $list['status']; ?>">
        			<td style="padding-bottom: 15px;width:200px;"><?php echo $list['rotid']; ?></td>
        			<td style="padding-bottom: 15px;width:300px;"><?php echo $list['sn']; ?></td>
        			<td style="padding-bottom: 15px;width:150px;"><?php getStatus($list['status']); ?></td>
        			<td style="padding-bottom: 15px;width:200px;">
    				<?php switch($list['status']){ 
    					case 0:
    					case 10:
    						echo '<a class="preview-list" href="#" status="' . $list['status'] . '" rotid="' . $list['rotid'] . '">View</a>';
    					break;
    					case 1:
    						echo '<a class="preview-list" href="#" status="' . $list['status'] . '" rotid="' . $list['rotid'] . '">Process</a>';
    					break;
    					case 2:
    						echo '<a class="preview-list" href="#" status="' . $list['status'] . '" rotid="' . $list['rotid'] . '">Reason</a>';
    					break;
    				} ?>
    				</td>
        		</tr>
				<tr style="margin-top: -19px;width:90%;background:#F8F8F8">
					<td colspan="4" style="text-indent:10px;"><span style="display: block;margin-top: -20px;">Item/s : <a style="color: #59b7c2;"><?php echo $list['name']; ?></a>, 
				<?php $lass = $list['rotid']; } ?>
    		<?php } ?>
<?php } else if ($this->get('list')==1) { ?>
<script type="text/javascript" src="<?php $this->path('js/jquery.highlight.js');?>"></script>
<script type="text/javascript" src="<?php $this->path('js/ui/ui.tabs.js');?>"></script>
<div style="height: 340px;overflow: auto;margin-bottom:-10px">
	<div>Search Item&emsp;<input id="searchsup" type="text" style="width:40%" /></div>
	<br />
	<div style="height: 280px;position: relative;display: block;overflow: hidden;">
        <div id="tabs" style="height:258px;">
            <ul>
            	<li><a href="#tabs-1">Pending</a></li>
           		<li><a href="#tabs-2">Processed</a></li>
            	<li><a href="#tabs-3">Canceled</a></li>
            	<li><a href="#tabs-4">Confirmation</a></li>
            </ul>
            <div id="tabs-1">
            	<table class="suplisting" style="margin:0px;">
                	<thead>
                		<tr style="display:block;position:relative;">
                			<th class="bg" style="width:200px;">PO #</th>
                			<th style="width:300px;">Supplier</th>
                			<th class="bg" style="width:150px;">Status</th>
                			<th style="width:200px;">List</th>
                		</tr>
            		</thead>
            		<tbody show="0" style="height: 150px;overflow: auto;display: block;width:100%;">
            		</tbody>
            	</table>
            </div>
            <div id="tabs-2">
            	<table class="suplisting" style="margin:0px;">
                	<thead>
                		<tr style="display:block;position:relative;">
                			<th class="bg" style="width:200px;">PO #</th>
                			<th style="width:300px;">Supplier</th>
                			<th class="bg" style="width:150px;">Status</th>
                			<th style="width:200px;">List</th>
                		</tr>
            		</thead>
            		<tbody show="10" style="height: 150px;overflow: auto;display: block;width:100%;">
            		</tbody>
            	</table>
            </div>
            <div id="tabs-3">
            	<table class="suplisting" style="margin:0px;">
                	<thead>
                		<tr style="display:block;position:relative;">
                			<th class="bg" style="width:200px;">PO #</th>
                			<th style="width:300px;">Supplier</th>
                			<th class="bg" style="width:150px;">Status</th>
                			<th style="width:200px;">List</th>
                		</tr>
            		</thead>
            		<tbody show="2" style="height: 150px;overflow: auto;display: block;width:100%;">
            		</tbody>
            	</table>
            </div>
            <div id="tabs-4">
            	<table class="suplisting" style="margin:0px;">
                	<thead>
                		<tr style="display:block;position:relative;">
                			<th class="bg" style="width:200px;">PO #</th>
                			<th style="width:500px;">Supplier</th>
                			<th style="width:300px;">Option</th>
                		</tr>
            		</thead>
            		<tbody confirm="1" show="0" style="height: 150px;overflow: auto;display: block;width:100%;">
            		</tbody>
            	</table>
			</div>
        </div>
	</div>
	<div id="displayer" title="Preview"></div>
	<script>
    	var func2 = function(){
    		$('.suplisting tbody tr:nth-child(even)').each(function(){
				var st = $(this).find('span').html();
				st = st.split("").reverse().join("");
				st = st.replace(",","").split("").reverse().join("");
				$(this).find('span').html(st);
				if($(this).parent().attr('confirm') == 1){
					//$(this).remove();
				}
			});
    		$('.suplisting tbody tr:nth-child(odd)').each(function(){
    			if($(this).hasClass('list')){
					if($(this).attr('status') != $(this).parent().attr('show')){
						if(!($(this).attr('status') == 1 && $(this).parent().attr('show') == 0))
							$(this).hide();
					}
					if($('#searchsup').val().length == 0){
            			$(this).find('td').each(function(){
            				$(this).css("padding-bottom","0px");
            			});
        				$(this).next().hide();
					}
        			$(this).click(function(){
    					if($(this).next().css('display') == 'none'){
            				$(this).next().fadeIn();
              				$(this).find('td').each(function(){
              					$(this).css("padding-bottom","15px");
              				});
    					}else{
            				$(this).next().hide();
            				$(this).find('td').each(function(){
            					$(this).css("padding-bottom","0px");
            				});
    					}
        			});
					if($(this).parent().attr('confirm') == 1){
						if($(this).attr('status') == 1)
							$(this).hide();
                        var orid = $(this).find('td:first-child()').text();
						$(this).find('td:nth-child(4)').html("<select style='width:150px;' ><option value='0'>Select</option><option value='1'>Confirm</option><option value='2'>Cancel</option></select>").find('select').selectBox().change(function() {
                          	if($(this).val() != 0){
								var flag = $(this).val();
                          		$.post('?module=pos&action=inventory&action2=reorder&page=receive&ajax=true', {setor:1, id:orid, flag:flag}, function(data){console.log(data);$('#searchsup').trigger('keyup');});
                          	}
});
						$(this).find('td:nth-child(3)').remove();
						$(this).unbind('click');
					}
    			}
    		});
			
    		$('.preview-list').click(function(e){
				e.preventDefault();
				e.stopPropagation();
    			var status = $(this).attr('status');
    			var rs = $(this);
    			if(status == 1){	$.post('?module=pos&action=inventory&action2=reorder&page=receive&ajax=true',{rotid:$(this).attr('rotid'),list:0},function(data){
          				$('#displayer').html(data);
                        /*$('#dialog-form-all').dialog({
                              	height: 630,
                              	width: 800,
                              	modal: true,
                              	resizable: false
                         });*/
          				$('#displayer').dialog('open');
          			});
      			}else{	$.post('?module=pos&action=inventory&action2=reorder&ajax=true',{rotid:$(this).attr('rotid'),preview:1,isprocessorder:1,status:status},function(data){
          				$('#displayer').html(data);
          				if(status == 2){
                              $('#dialog-form-all').dialog({
                              	height: 630,
                              	width: 800,
                              	modal: true,
                              	resizable: false
                              });
          				}
          				$('#displayer').dialog('open');
          			});
    			}
    		});
    	}
		$('#displayer').dialog({
            autoOpen: false,
            height: 600,
            width: 800,
            modal: true,
            resizable: false
		});
		$('#searchsup').keyup(function(){
			var key = $('#searchsup').val();
			delay(function(){
				$.post('?module=pos&action=inventory&action2=reorder&ajax=true&page=receive&list=1',
					{key:key,issearching:1},function(data){
						$('.suplisting tbody').hide().html(data).fadeIn();
						func2();
						//$('#suplisting tbody tr:nth-child(even)').highlight(key);
					});
    		}, 600 );
		});
		func2();
		$('#tabs').tabs();
		$('#searchsup').trigger('keyup');
		$('#tabs ul li a').click(function(){
			$('.suplisting tbody').hide();
			$('#searchsup').trigger('keyup');
		});
	</script>
</div>
<?php } else { ?>
<form id="send-po" onsubmit="return " class="form_style registed product_page finished" style="width:93%;margin-top:1px;min-height:490px">
	<strong>Processing purchased item from <?php echo $supplier['name']; ?></strong>
	<table id="delprocessing">
		<thead>
			<th style="width:325px" class="bg">Item</th>
			<th style="width:110px">Unit</th>
			<th style="width:110px" class="bg">Quantity</th>
			<th style="width:91px">Price</th>
			<th style="width:81px" class="bg">Item Received</th>
		</thead>
		<tbody>
			<?php 
				foreach($orders as $order){
    				getDetail($order['iid'], $order['sdid'], $order['quantity']);
				}
			?>
		</tbody>
	</table>
	<input type="button" id="devsub" value="Done" style="float:right;" />
	<div class="clear"></div>
</form>
<script>
	$('.rqty').keyup(function(){
		if($(this).val().length == 0 || $(this).val() <= 0){
			$(this).hide().prev().fadeIn();
		}
 		if($(this).val() != $(this).attr('preval'))
			$(this).css('font-weight','bold');
		else
			$(this).css('font-weight','normal');
		if( isNaN($(this).val()) ){
			$(this).val($(this).val().substring(0,$(this).val().length-1));
		}else{
			if($(this).val()*1 > $(this).attr('preval')*1){
				if(!confirm("Value is too high than the ordered quantity. Continue?")){
					$(this).val($(this).val().substring(0,$(this).val().length-1));
				}
			}
		}
	});
	$('.brqty').click(function(){
		$(this).hide().next().fadeIn().val($(this).next().attr('preval'));
	});
	$('#devsub').click(function(){
		var reorders=new Array(); 
		var x = 0;
		$('#delprocessing').find('.rqty').each(function(){
			if($(this).css('display') != 'none'){
				var iid = $(this).parent().parent().attr('iid');
				reorders[x++] = new Array(iid,$(this).val(),<?php echo $supplier['sdid']; ?>);
			}
		});
    	$.ajax({
			type: "POST",
			data: {orders:reorders,isreceiveorder:1,total:x,rotid:<?php echo $rotid; ?>},
			url: "?module=pos&action=inventory&action2=reorder&page=receive&ajax=true",
            success: function(data){
				console.log(data);
		   		$('#displayer').dialog('close');
				//$('#dialog-form-all').dialog('close');
				$('#reorder-list').trigger('click');
				reload_listing();
		   }
    	});
	});
</script>
<?php } ?>